#include <linux/mallocator.h>
#include <linux/memheap.h>

#include "tlsf.h"

static void *__tlsf_malloc(struct mallocator *m, unsigned long size, gfp_t flags, int node)
{
    return LOS_MemAlloc(m->start, size);
}

static void __tlsf_free(struct mallocator *m, const void *object)
{
    LOS_MemFree(m->start, object);
}

int memheap_add(void *start, void *end, unsigned int flags)
{
    struct mallocator *ma = start;

    start += sizeof(struct mallocator);

    OsMemPoolInit(start, end - start);

    ma->alloc = __tlsf_malloc;
    ma->free = __tlsf_free;
    ma->flags = flags;
    ma->start = start;
    ma->size = end - start;

    mallocator_register(ma);

    return 0;
}
